//
//  FTNetWorkTool.swift
//  Weibo
//
//  Created by 方焘 on 16/6/11.
//  Copyright © 2016年 taofang. All rights reserved.
///Users/leo/Desktop/SWift代码/新浪微博/FTWeibo/Weibo/Weibo/classes/Tools/FTNetWorkTools.swift:33:13: 'GET(_:parameters:success:failure:)' is deprecated
import UIKit
import AFNetworking

enum httpRequesetMethod: String {
    case GET = "GET"
    case POST = "POST"
}

class FTNetWorkTools: AFHTTPSessionManager {
    //单例
    static let sharedToools: FTNetWorkTools = {
        let instance = FTNetWorkTools(baseURL: nil)
        instance.responseSerializer.acceptableContentTypes?.insert("text/html")
        return instance
    }()
    
    func requet(method: httpRequesetMethod, urlString: String, parameters: AnyObject?, finished:(result:AnyObject?, error: NSError?)->()) {
        
        let success = {(task: NSURLSessionDataTask, result: AnyObject?) in
            finished(result: result, error: nil)
        }
        let failure = {(task: NSURLSessionDataTask?, error: NSError) -> Void in
            print(error)
            finished(result: nil, error: error)
        }
        
        if method == .GET {
            GET(urlString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            POST(urlString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    }

}
